import Collapse from 'components/Markdown/Collapse'

export const meta = {
  title: 'GraphQL Requests (JavaScript)',
  position: 100,
  technology: "node",
  technologyOrder: 1,
  articleGroup: "GraphQL Requests",
}

## Overview

The Prisma client lets you send GraphQL queries and mutations directly to your Prisma service using the `$request` method:

```ts
$request: <T = any>(query: string, variables?: {[key: string]: any}) => Promise<T>;
```

### Examples

_Fetching a single user_:

```js
const query = `
  query {
    user(id: "cjcdi63j80adw0146z7r59bn5") {
      id
      name
    }
  }
`

prisma.request(query)
  .then(result => console.log(result))
// sample result:
// {"data": { "user": { "id": "cjcdi63j80adw0146z7r59bn5", "name": "Sarah" } } }
```


_Fetching a single user using variables_:

```js
const query = `
  query ($userId: ID!){
    user(id: $userId) {
      id
      name
    }
  }
`

const variables = { userId: 'cjcdi63j80adw0146z7r59bn5' }

prisma.request(query, variables)
  .then(result => console.log(result))
// sample result:
// {"data": { "user": { "id": "cjcdi63j80adw0146z7r59bn5", "name": "Sarah" } } }
```
